home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-10 | 3.6 KB | 138 lines | [TEXT/MPS ] |
- cr1: equ 1
-
- ;
- ; File: Timer.s
- ;
- ; Copyright: © 1993-1994 by Apple Computer, Inc., all rights reserved.
- ;
- ; This sample contains three routines for using the RTC (Real Time Clock) on
- ; PowerPC 601 chip.
- ;
- ; WARNING
- ; IMPORTANT!!: The RTC is only available on the 601 and this code will crash if
- ; run on any other PowerPC chips. Do not use this code in a shipping product.
- ;
- ; This code is written from the asmSample in the PPC SDK
- ;
-
-
- linkageArea: set 24 ; constant comes from the PowerPC Runtime Architecture Document
- CalleesParams: set 32 ; always leave space for GPR's 3-10
- CalleesLocalVars: set 0 ; MicroSecondsRTC doesn't have any
- numGPRs: set 0 ; num volitile GPR's (GPR's 13-31) used by MicroSecondsRTC
- numFPRs: set 0 ; num volitile FPR's (FPR's 14-31) used by MicroSecondsRTC
-
- spaceToSave: set linkageArea + CalleesParams + CalleesLocalVars + 4*numGPRs + 8*numFPRs
-
-
- ; Need to export both the function descriptor and an entry point for
- ; MicroSecondsRTC. The function entry point doesn't have to be a csect
- ; name - it can be a regular label. Since PPCC puts a '.' in front of
- ; function names, the entry point label's name must begin with a '.'
-
- export MicroSecondsRTC[DS]
- export .MicroSecondsRTC[PR]
-
- ; create a TOC entry for the the function. This is
-
- toc MicroSecondsRTC, MicroSecondsRTC[DS]
-
- ; The function descriptor contains definitions used for runtime linkage
- ; of the function. The address of the function entry point must be in
- ; the first longword. The address of the start of the TOC for the
- ; module that contains the function (use the predefined PPCAsm
- ; global tc0) must be in the second longword. The third longword
- ; contains the environment pointer, which is not used by C and so is set
- ; to 0.
-
- csect MicroSecondsRTC[DS]
- dc.l .MicroSecondsRTC[PR]
- dc.l TOC[tc0]
- dc.l 0
-
-
- ; This is the actual code of the MicroSecondsRTC function
-
- csect .MicroSecondsRTC[PR]
-
- ; PROLOGUE: called routine's responsibilities
- ; mflr r0 ; Get link register
- ; stw r0, 0x0008(SP) ; Store the link resgister on the stack
- ; stwu SP, -spaceToSave(SP) ; skip over the stack space where the caller
- ; might have saved stuff
-
- ; We are a leaf function so we don't need to do the prologue or epilogue
-
- ; FUNCTION BODY
- load_RTC:
- mfspr r3, 4 ; dc.l 0x7C6402A6, mfspr r3, RTCU
- mfspr r4, 5 ; dc.l 0x7C8502A6, mfspr r4, RTCL
- mfspr r5, 4 ; dc.l 0x7CA402A6, mfspr r5, RTCU
-
- cmpw r3, r5
- bne load_RTC
-
- li r6, 1000
- divwu r4, r4, r6
-
- lis r5,15 ; Multiply the seconds times 1,000,000
- ori r5,r5,0x4240
- mullw r3,r3,r5
-
- add r3, r3, r4
-
- ; EPILOGUE: return sequence
- ; lwz r0, 0x8+spaceToSave(SP) ; Get the saved link register
- ; addic SP, SP, spaceToSave ; Reset the stack pointer
- ; mtlr r0 ; Reset the link register
- blr ; return via the link register
-
-
-
-
-
- export FetchRTCU[DS]
- export .FetchRTCU[PR]
-
- ; create a TOC entry for the the function. This is
-
- toc FetchRTCU, FetchRTCU[DS]
-
- csect FetchRTCU[DS]
- dc.l .FetchRTCU[PR]
- dc.l TOC[tc0]
- dc.l 0
-
-
- ; This is the actual code of the FetchRTCU function
-
- csect .FetchRTCU[PR]
-
- ; FUNCTION BODY
- mfspr r3, 4 ; dc.l 0x7C6402A6, mfspr r3, RTCU
- blr ; return via the link register
-
-
-
-
- export FetchRTCL[DS]
- export .FetchRTCL[PR]
-
- ; create a TOC entry for the the function. This is
-
- toc FetchRTCL, FetchRTCL[DS]
-
- csect FetchRTCL[DS]
- dc.l .FetchRTCL[PR]
- dc.l TOC[tc0]
- dc.l 0
-
-
- ; This is the actual code of the FetchRTCL function
-
- csect .FetchRTCL[PR]
-
- ; FUNCTION BODY
- mfspr r3, 5 ; mfspr r3, RTCL
- blr ; return via the link register
-